package com.niuwa.quartz.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.niuwa.p2p.core.mvc.entity.PageBean;
import com.niuwa.p2p.entity.PageQuery;
import com.niuwa.quartz.dao.job.JobDao;
import com.niuwa.quartz.entity.JobEntity;
import com.niuwa.quartz.vo.JobVo;

@Service
public class JobService {

	@Autowired
	private JobDao jobDao;

	public JobEntity getJobById(Long jobId) {
		return jobDao.getJobById(jobId);
	}

	public List<JobEntity> getActiveJob() {
		return jobDao.getActiveJob();
	}

	public void updateJob(JobEntity jobEntity) {
		jobDao.updateJob(jobEntity);
	}

	public void saveJob(JobEntity jobEntity) {
		jobDao.saveJob(jobEntity);
	}

	public PageBean<JobVo> selectJobs(Map<String, Object> paramMap) {
		assert paramMap.get(PageQuery.PAGEQUERY) != null;
		// 总条数
		int totalCount = jobDao.selectCountJobBySelective(paramMap);
		PageBean<JobVo> page = new PageBean<JobVo>(totalCount);
		// 当前页
		page.setPage(((PageQuery) paramMap.get(PageQuery.PAGEQUERY)).getPage());
		page.setRows(jobDao.selectJobBySelective(paramMap));
		return page;
	}
	
	public void delJob(JobEntity jobEntity){
		jobDao.delJob(jobEntity);
	}
}
